--[[***************************
   Copyright (c) 2012 TPV R&D Center Brazil
   All Rights Reserved
 ***********************]]

--- toolkit.component.SignalMeter

local SignalMeter = Box:new()

function SignalMeter:new(o)
   if(type(o) ~= 'table') then
      o = {}
   end

   local newProgress = Box:new(o)
   
   newProgress.parent = nil

   newProgress.backContent = nil
   newProgress.barContent = nil

   newProgress.componentType = "SignalMeter"

   newProgress.minValue = o.minValue or 0
   newProgress.maxValue = o.minValue or 100

   newProgress.noLabel = o.noLabel or false

   newProgress.value = newProgress.minValue

   tmpLabel = Label:new({
      align = 'CENTER',
      width = 140
   })
   tmpLabel:setActivated({
      size = 35,
      color = {241, 241, 241, 255},
      style = 'Bold',
   })

   newProgress.label = o.label or tmpLabel
   newProgress.label:setText(tostring(newProgress.value))

   newProgress.backGround = o.backGround or nil
   newProgress.foreGround = o.foreGround or nil

   --generate an object
   setmetatable(newProgress, self)
   self.__index = self

   return newProgress
end

function SignalMeter:setValue(newValue, update)
   if(newValue ~= self.value) then
      if(newValue < self.minValue) then
         newValue = self.minValue
      elseif(newValue > self.maxValue) then
         newValue = self.maxValue
      end
      --set new value
      self.value = newValue
      if(self.label ~= nil) then
         self.label:setText(tostring(math.floor(self.value)))
      end
   end
   if (update) then
      self.parent:updateSignalMeter(self)
   end
end

function SignalMeter:dispose()
   self.backContent = nil
   self.barContent = nil
   collectgarbage()
end

return SignalMeter
